package com.kasax.eventbus;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.kasax.bus.corel.EventBus;
import com.kasax.bus.utils.GsonUtils;
import com.kasax.bus.utils.LogUtils;
import com.kasax.bus.anno.Subscribe;
import com.kasax.bus.corel.ThreadMode;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void receive(Firend firend) {
        LogUtils.i(getClass(), "receive firend: " + firend);
        Toast.makeText(this, "firend: " + GsonUtils.toJson(firend), Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unRegister(this);
    }

    public void handleGoTestPage(View view) {
        startActivity(new Intent(this, SecondaryActivity.class));
    }
}